
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <!-- 引入 Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .card {
            width: 100%;
            max-width: 400px;
            padding: 20px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
        }
        .card h1 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 24px;
            font-weight: bold;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            font-weight: bold;
        }
        .btn-primary {
            width: 100%;
            padding: 10px;
            font-size: 16px;
        }
        .error-message {
            color: red;
            text-align: center;
            margin-top: 10px;
        }
        .login-link {
            text-align: center;
            margin-top: 15px;
        }
    </style>
</head>
<body>
<div class="card">
    <h1>注册</h1>
    <form action="/auth/register" method="post" onsubmit="return validatePassword()">
        <div class="form-group">
            <label for="username">用户名:</label>
            <input type="text" id="username" name="username" class="form-control" required>
        </div>
        <div class="form-group">
            <label for="fullName">姓名:</label>
            <input type="text" id="fullName" name="fullName" class="form-control">
        </div>
        <div class="form-group">
            <label for="email">邮箱:</label>
            <input type="email" id="email" name="email" class="form-control">
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" class="form-control" required minlength="6">
            <small class="form-text text-muted">密码长度不能少于6个字符</small>
        </div>
        <div class="form-group">
            <label for="confirmPassword">确认密码:</label>
            <input type="password" id="confirmPassword" name="confirmPassword" class="form-control" required minlength="6">
        </div>
        <button type="submit" class="btn btn-primary">注册</button>
    </form>
    <p class="error-message" th:if="${error}" th:text="${error}"></p>
    <div class="login-link">
        <a href="/auth/login">已有账号？立即登录</a>
    </div>
</div>

<script>
    // 前端验证密码是否一致
    function validatePassword() {
        const password = document.getElementById("password").value;
        const confirmPassword = document.getElementById("confirmPassword").value;

        if (password !== confirmPassword) {
            alert("两次输入的密码不一致，请重新输入！");
            return false; // 阻止表单提交
        }
        return true; // 允许表单提交
    }
</script>
</body>
</html>